package com.az;

import java.util.logging.Level;

import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.impls.automation.IJIDispatch;

public class MainApplet extends JApplet {

	// ===========================================================
	// Constants
	// ===========================================================
	String domain = "WORKGROUP";
	String hostname = "mac-pk-ahaider";
	String username = "aizaz.haider";
	String password = "hello";
	// ===========================================================
	// Fields
	// ===========================================================
	public JIComServer comServer = null;

	public JISession dcomSession = null;

	public IJIDispatch wbemServices = null;

	public Object[] params = null;

	public static final String diskMonitors = "Win32_PerfFormattedData_PerfDisk_LogicalDisk";

	public static final String operatingSystem = "Win32_OperatingSystem";

	public static final String memoryMonitors = "Win32_PerfRawData_PerfOS_Memory";

	public static final String procMonit = "Win32_PerfFormattedData_PerfOS_Processor";

	public static final String systemMonit = "Win32_PerfFormattedData_PerfOS_Processor";

	public String memoryStatus = "Win32_OperatingSystem";

	public String cpuUsage = "Win32_PerfFormattedData_PerfProc_Process";

	public String windowsDiskInfo = "Win32_LogicalDisk";

	private long totalDiskUsage = 0;

	private long freeDiskUsage = 0;

	// ===========================================================
	// Constructors
	// ===========================================================

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
	@Override
	public void init() {
		super.init();
		try {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					JLabel labale = new JLabel("Label 1");
					add(labale);
				};
			});
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	// ===========================================================
	// Methods
	// ===========================================================
	public void setWindowsCredentials(String domain, String hostname, String username, String password) {
		try {
			dcomSession = init(domain, username, password);
			
			

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (dcomSession != null) {
				try {
					JISession.destroySession(dcomSession);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}

	}

	private static JISession init(String domain, String user, String pass) throws Exception {
		JISystem.getLogger().setLevel(Level.ALL);
		JISystem.setAutoRegisteration(true);

		JISession dcomSession = JISession.createSession(domain, user, pass);
		dcomSession.useSessionSecurity(true);
		return dcomSession;
	}
	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================

}
